home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 44
/
Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso
/
-in_the_mag-
/
basics
/
hisoft
/
doc2rtf.lha
/
DOC2RTF.bas
< prev
next >
Wrap
BASIC Source File
|
1996-05-20
|
30KB
|
1,153 lines
REM ------------------------------
REM DOC2RTF.bas - Mark J Swift
REM Originally Qdos SuperBASIC
REM HiSoft BASIC 2 version SNG
REM Update v4.0, 19th May 1996
REM ------------------------------
REM Now supports PC Quill DOCs
REM as well as QL + Thor files
REM adapts for screen size and
REM converts PC and QL to ANSI
REM ------------------------------
' Works from Command Line or Workbench - expects ASL
' (WB2+ or PD versions) for Workbench file selector.
'
' Main v 1.012 advance is PC Quill document support.
' Workbench view is not yet properly font adaptive -
' text above 8 pitch overlaps progress indicator and
' may be too big for the window if average character
' width is more than eight pixels. Use a fixed font?
' Probably better to resize the window for the font!
' v 1.013 includes a lot of fixes and fudges to make
' output more closely resemble that from the version
' for the QL (1.01) from which this is derived but X
' coordinates (default tabs etc) are still adrift by
' a small margin - perhaps because of Floating Point
' rounding effects? Main window + ASL requesters now
' use extra Workbench screen lines if available, but
' should still be compatible with NTSC, no overscan.
' STILL not font adaptive, but completion indication
' has been moved to steer clear of most small fonts;
' looks fine in Topaz 8, Courier 13, LetterGothic 15
' Clean 13, System 8, Teletext 10 and smaller fonts.
' Version 1.014 selects ANSI and escapes codes >127.
' cWidth has been tweaked by 0.2% to match QL maths.
' Update restores an extra tab for left indentation.
' Completion indicator centred in box. Mouse polling
' improved. Busy wait for mouse debounce eliminated.
REM $INCLUDE asl.bh ' HiSoft's ASL Requester support
' Globals predominate
DIM SHARED DOCbldFlg%,DOCitaFlg%,DOCundFlg%,DOCcndFlg%,DOCsupFlg%,DOCsubFlg%
DIM SHARED RTFbldFlg%,RTFitaFlg%,RTFundFlg%,RTFcndFlg%,RTFsupFlg%
DIM SHARED RTFsubFlg%,RTFenhFlg%,PCtype% ' 1.012
DIM SHARED RTFdefli,RTFdeffi,RTFdefri,RTFli,RTFfi,RTFri
DIM SHARED RTFalignFlg%,RTFstyleFlg%,RTFparFlg%,RTFnTbs%
DIM SHARED RTFo$,RTFtbs$
DIM SHARED base6&,base7&,File$,InFile$,OutFile$,t,txtOffs&,tblOffs&,cWdth
DIM SHARED tblLen&,PagOffs,PagLen,GenOffs,GenLen,RulOffs,RulLen
DIM SHARED DOCrulID,DOCbotM,DOCpwid,RTFpwid,DOCLineGap,DOCLinePP,DOCjFlg
DIM SHARED DOCStartPag,DOCtopM,DOChjust,DOCfjust,DOChGap,DOCfGap
DIM SHARED RTFextra,RTFheadery,RTFfootery,RTFmargt,RTFmargb,RTFstartPag
DIM SHARED RTFmargl,RTFmargr,DOCpagFlg%,RTFleading,QUILL
' No need to DIM strings only used in the mainline (Turbo static allocation)
'DIM InFile$(100),OutFile$(100),verstag$(4)
'DIM RTFtbs$(256),K$(1),extra$(4),RTFo$(4096)
' Global arrays
1170 DIM SHARED RTFtbs%(256),ANSI%(255)
' cWidth trimmed down (from 11880 to 11858, < 0.2%) to match QL arithmetic
cWidth=11858 : cWidth=cWidth/98:' width of 10pt courier in 1/20 pts (approx)
verstag$="$VER: DOC2RTF 1.014 (19 May 1996)"' this version from Mark's 1.01
RTFtbs$=STRING$(256,CHR$(0)) ' Kludge to prevent ASC on empty string abort
CommandLine%=LEN(COMMAND$)
IF CommandLine%=0
LIBRARY OPEN "asl.library"
DIM frintags&(20) ' ASL Tag arrays
DIM frouttags&(20)
OutDrawer$="RAM:" ' Path defaults
InDrawer$="QL0:"
InName$="_doc"
extraR%=(PEEKW(SYSTAB+2)-200)\2 ' Add to file requester
extra%=extraR%
IF extraR%>18 THEN extra%=18 ' Add to window is limited
END IF
REPEAT outer_loop
IF CommandLine%
' we have a command line - try to parse it
InFile$=COMMAND$
IF INSTR(InFile$,"?") THEN
PRINT "Example: DOC2RTF InFile [OutFile]" ' Too terse?
SYSTEM
END IF
gap%=INSTR(InFile$," ")
gap1%=gap%
REPEAT closeUp
IF gap%=0 THEN EXIT closeUp
IF gap%>=LEN(InFile$) THEN gap%=0 : EXIT closeUp
IF MID$(Infile$,gap%+1,1)<"!"
gap%=gap%+1
ELSE
EXIT closeUp
END IF
END REPEAT closeUp
IF gap%=0
OutFile$=InFile$+".RTF"
ELSE
IF UCASE$(MID$(InFile$,gap%+1,2))="TO" AND MID$(InFile$,gap%+3,1)<"!"
OutFile$=MID$(InFile$,gap%+3,1024)
ELSE
OutFile$=MID$(InFile$,gap%+1,1024)
END IF
REPEAT tidy
IF LEFT$(OutFile$,1)<"!"
OutFile$=MID$(OutFile$,2,1024)
ELSE
EXIT tidy ' Controls and spaces stripped from start
END IF
END REPEAT tidy
InFile$=LEFT$(InFile$,gap1%-1) ' Keep up to first space
END IF
PRINT "Converting from ";Infile$;" TO ";Outfile$
ELSE
' Use Workbench screen (assume >= 640x200) ' SCREEN 1,640,200,LOG2(2),4
WINDOW 1," DOC2RTF by Mark J Swift, version " + MID$(verstag$,14,7), _
(40,2+extra%)-(600,198+extra%),2+4+16+256
WIDTH 72 ' Try to ensure text leaves room for a progress bar on the right
CLS
PRINT " DOC2RTF is a file utility that translates Psion `Quill' DOC files into"
PRINT " rich text format (RTF). RTF files can be imported by Amiga Wordworth 5"
PRINT " or many Apple Macintosh & IBM PC word-processors and DTP applications."
PRINT
PRINT " FREEWARE by Mark J Swift, Rear Flat, 175 Church Street, Blackpool, FY1"
PRINT " 3NX, UK then converted to Amiga HiSoft BASIC 2 and extended by Simon N"
PRINT " Goodwin May 1995 to May 1996 using extra information from Chas Dillon."
PRINT
' No command line so use the ASL file requester (expects WB2 and up)
TAGLIST VARPTR(frintags&(0)),ASLFR_TitleText&,"Quill file selector", _
ASLFR_InitialFile&,InName$, _
ASLFR_InitialDrawer&, InDrawer$, _
ASLFR_InitialHeight&, 150+ExtraR%, _
ASLFR_InitialLeftEdge&, 320, _
ASLFR_InitialTopEdge&, 50+extraR%, _
TAG_DONE&
fr&=AllocAslRequest&(ASL_FileRequest&,VARPTR(frintags&(0)))
IF fr& THEN
IF AslRequest&(fr&,0) THEN
' A file name was entered; build the full path
InDrawer$=PEEK$(PEEKL(fr&+fr_Drawer%)): filename$=InDrawer$
IF RIGHT$(InDrawer$,1)<>":" THEN filename$=filename$+"/"
InName$=PEEK$(PEEKL(fr&+fr_File%))
filename$=filename$+InName$
ELSE
filename$=""
END IF
FreeASlRequest fr&
InFile$=filename$
PRINT " Reading from ";InFile$
ELSE
INPUT " Input source DOC filename >";InFile$
END IF
IF InFile$="" THEN EXIT outer_loop
IF UCASE$(RIGHT$(InName$,3))="DOC" ' v 1.012 allows .DOC and _DOC
OutFile$=LEFT$(InName$,LEN(InName$)-3)+"RTF"
ELSE
OutFile$=InName$+".RTF"
END IF
TAGLIST VARPTR(frouttags&(0)), _
ASLFR_TitleText&,"Rich Text Format file selector", _
ASLFR_InitialFile&, OutFile$, _
ASLFR_InitialDrawer&, OutDrawer$, _
ASLFR_InitialHeight&, 150+extraR%, _
ASLFR_InitialLeftEdge&, 310, _
ASLFR_InitialTopEdge&, 50+extraR%, _
TAG_DONE&
fr&=AllocAslRequest&(ASL_FileRequest&,VARPTR(frouttags&(0)))
IF fr& THEN
IF AslRequest&(fr&,0) THEN
' A file name was entered; build the full path
filename$=PEEK$(PEEKL(fr&+fr_Drawer%))
IF RIGHT$(filename$,1)<>":" THEN filename$=filename$+"/"
filename$=filename$+PEEK$(PEEKL(fr&+fr_File%))
ELSE
filename$=""
END IF
FreeASlRequest fr&
OutFile$=filename$
PRINT " Writing to ";OutFile$
ELSE
INPUT " Input destination RTF filename >";OutFile$
END IF
IF OutFile$="" THEN EXIT outer_loop
PRINT " Loading...";
LINE (519,61)-(569,176),0,bf
LINE (519,61)-(569,176),2,b
LINE (520,62)-(570,177),1,b
END IF ' Interactive
' Process entire document, a paragraph at a time
DOCbeginDocument InFile$
IF QUILL=0
PRINT InFile$;" is not a Quill document!"
IF CommandLine% THEN SYSTEM
PRINT " Please tap to continue, then make another selection."
ELSE
IF CommandLine%=0 THEN PRINT " Converting...";
RTFleading=240
IF (DOChjust<>0) THEN CALL DOCdoHeader
IF (DOCfjust<>0) THEN CALL DOCdoFooter
CALL DOCclearEnhance
Base6&=Base6&+14+14 ' 1.013, skip header and footer
RTFleading=240*(1+DOCLineGap)
REPEAT tblLoop
IF Base7&>tblOffs& THEN EXIT tblLoop
DOCdoParagraph
IF CommandLine%=0
IF txtOffs&>tblOffs& THEN
LINE (530,69)-(560,169),1,bf
ELSE
LINE (530,69)-(560,69+txtOffs&*100\tblOffs&),1,bf
END IF
END IF
END REPEAT tblLoop
CALL DOCendDocument
REM RETRY_HERE
IF CommandLine% THEN EXIT outer_loop
PRINT " Done - tap to continue.";
END IF
CALL MouseWait
END REPEAT outer_loop
SYSTEM ' Formerly STOP but no need for keypress
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Amiga specific routines
SUB MouseWait
LOCAL key$ ' No need to share here
REPEAT debounce
IF MOUSE(0)<2 THEN EXIT debounce
SLEEP
END REPEAT debounce
REPEAT poll
SLEEP : key$=INKEY$
IF MOUSE(0) THEN key$=CHR$(0)
IF LEN(key$) THEN EXIT poll
END REPEAT poll
END SUB ' MouseWait
REM NUM$ is a replacement for STR$ with two advantages:
REM Includes Zero before the point in numbers from 0..1
REM No leading space before positive numbers (bug-fix).
FUNCTION NUM$(VAL x)
STATIC t$
t$=STR$(x)
IF x>=0
t$=MID$(t$,2,15)
IF x<1 AND x>=.1 THEN t$="0"+t$
END IF
IF RIGHT$(t$,1)=" " THEN t$=LEFT$(t$,LEN(t$)-1) :REM Skip trailing space
NUM$=t$
END FUNCTION
' v 1.012 - PC little-endian byte reversal functions
FUNCTION WORD&(t$)
IF PCtype%
WORD&=ASC(LEFT$(t$,1))+256*ASC(MID$(t$,2,1))
ELSE
WORD&=CVI(t$)
END IF
END FUNCTION
FUNCTION LONG&(t$)
IF PCtype%
LONG&=WORD&(LEFT$(t$,2))+65536*WORD&(MID$(t$,3,2))
ELSE
LONG&=CVL(t$)
END IF
END FUNCTION
FUNCTION HEX4$(b%)
HEX4$=MID$("0123456789abcdef",b%+1,1)
END FUNCTION
FUNCTION HEX8$(c%)
HEX8$=HEX4$(c% >> 4)+HEX4$(c% AND 15)
END FUNCTION
SUB SignedByte6
t=ASC(MID$(File$,Base6&,1))
IF t>128 THEN t=128-t
Base6&=Base6&+1
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Quill document input routines
SUB DOCbeginDocument(InFile$)
LOCAL length,K,PCtype% ' Update for PC Quill, 23/9/95
DIM SHARED cWidth
' Read file into a string for random access
OPEN InFile$ FOR INPUT AS #6
length=LOF(6)
File$=INPUT$(length,#6)
CLOSE #6
' Check it's a valid Psion Quill file
QUILL=0
IF length<512 THEN EXIT SUB
IF MID$(File$,3,8)<>"vrm1qdf0" THEN EXIT SUB
QUILL=1
' Distinguish between MSDOS and QDOS ASCII
PCtype%=CVI(LEFT$(File$,2))<>20
IF PCtype%
RESTORE PC_CODES
ELSE
RESTORE QL_CODES
END IF
FOR K=127 TO 255
READ ANSI%(K)
NEXT K
base7&=1 ' Position in string (SuperBASIC #7 file pointer)
tblOffs&=LONG&(MID$(File$,11,4))
base6&=tblOffs&+22+1
tblLen&=WORD&(MID$(File$,15,2))
PagOffs=tblOffs&+tblLen&
PagLen=WORD&(MID$(File$,17,2))
GenOffs=PagOffs+PagLen
GenLen=WORD&(MID$(File$,19,2))
RulOffs=GenOffs+20+PCtype%*2
RulLen=GenLen-20-PCtype%*2
GenLen=GenLen-RulLen
DOCclearEnhance
DOCrulID=0
DOCbotM=ASC(MID$(File$,GenOffs+1,1))
K=ASC(MID$(File$,GenOffs+2,1))
SELECT ON K
=1 :DOCpwid=40
=2 :DOCpwid=64
=REMAINDER :DOCpwid=80
END SELECT
RTFpwid=INT(cWidth*DOCpwid+.5)
DOCLineGap=ASC(MID$(File$,GenOffs+3-PCtype%,1))
DOCLinePP=ASC(MID$(File$,GenOffs+4-PCtype%,1))
DOCStartPag=ASC(MID$(File$,GenOffs+5-PCtype%,1))
PCtype%=PCtype%*2
' Skip Qdos display colour at +6 as well as colour at +2
DOCtopM=ASC(MID$(File$,GenOffs+7-PCtype%,1))
DOChjust=ASC(MID$(File$,GenOffs+15-PCtype%,1))
DOCfjust=ASC(MID$(File$,GenOffs+16-PCtype%,1))
DOChgap=ASC(MID$(File$,GenOffs+17-PCtype%,1))
DOCfGap=ASC(MID$(File$,GenOffs+18-PCtype%,1))
IF DOCLinePP>70 THEN DOCLinePP=70
RTFextra=240*(70-DOCLinePP)/2
RTFheadery=240*DOCtopM+RTFextra
RTFfootery=240*DOCbotM+RTFextra
RTFmargt=RTFheadery
IF (DOChjust<>0) THEN RTFmargt=RTFmargt+240*(1+DOChGap)
RTFmargb=RTFfootery
IF (DOCfjust<>0) THEN RTFmargb=RTFmargb+240*(DOCfGap+1)
RTFstartPag=DOCStartPag
CALL RTFbeginDocument(OutFile$)
END SUB
SUB DOCendDocument
CALL RTFendDocument
END SUB
SUB DOCdoFooter
SHARED File$
RTFbeginFooter
txtOffs&=LONG&(MID$(File$,tblOffs&+22+15,4))
DOCdoHeaderFooter(GenOffs+16-PCtype%)
CALL RTFendFooter
END SUB
SUB DOCdoHeader
RTFbeginHeader
txtOffs&=LONG&(MID$(File$,tblOffs&+23,4))
DOCdoHeaderFooter(GenOffs+15-PCtype%)
CALL RTFendHeader
END SUB
SUB DOCdoHeaderFooter(p&)
LOCAL Kk,k$,k
DOCclearEnhance
DOCjFLG=ASC(MID$(File$,p&,1))
SELECT ON DOCjFlg
=1:RTFleftAlign
=2:RTFcentreAlign
=3:RTFrightAlign
END SELECT
Kk=ASC(MID$(File$,p&+4,1))
IF Kk<>0 THEN CALL DOCbold
p&=txtOffs&+1
REPEAT txtLoop
IF p&>LEN(File$) THEN EXIT txtLoop
k$=MID$(File$,p&,1) : p&=p&+1
k=ASC(k$)
IF K=0 THEN EXIT txtLoop
CALL RTFoutChar(K$)
END REPEAT txtLoop
IF Kk<>0 THEN CALL DOCbold
REPEAT pnum
K=INSTR(RTFo$,"nnn")
IF K=0 THEN K=INSTR(RTFo$,"NNN")
IF K=0 THEN K=INSTR(RTFo$,"aaa")
IF K=0 THEN K=INSTR(RTFo$,"AAA")
IF K=0 THEN EXIT pnum
IF K=(LEN(RTFo$)-2) THEN
RTFo$=LEFT$(RTFo$,K-1)+"\chpgn "
ELSE
RTFo$=LEFT$(RTFo$,K-1)+"\chpgn "+MID$(RTFo$,K+3,99999)
END IF
END REPEAT pnum
END SUB
SUB DOCdoParagraph
LOCAL k%,p&,L%,I%,Kk% ' Indents changed for v 1.013
txtOffs&=1+LONG&(MID$(File$,Base6&,4))
DOCclearEnhance
IF txtOffs&<>0 THEN
Base7&=txtOffs&
Base6&=Base6&+7
CALL SignedByte6
RTFleftIndent INT((t+1)*cWidth+.5)
CALL SignedByte6
RTFfirstIndent (INT((t+1)*cWidth+.5)-RTFli)
CALL SignedByte6
RTFrightIndent INT(RTFpwid-t*cWidth+.5)
CALL SignedByte6
'1970 DOCjFlg=t
SELECT ON t
=0,4:RTFleftAlign
=1,5:RTFcentreAlign
=2,6:RTFjustify
END SELECT
K%=ASC(MID$(File$,Base6&,1))
Base6&=Base6&+3
IF K%<>DOCrulID THEN
DOCrulID=K%
p&=RulOffs+1
REPEAT loo
K%=ASC(MID$(File$,p&,1)) : p&=p&+1
L%=ASC(MID$(File$,p&,1))-2 : p&=p&+1 ' Fix? -2 in v 1.012
IF K%=DOCrulID THEN EXIT loo
IF L%>0 THEN p&=p&+L%
END REPEAT loo
RTFnTbs%=0
FOR I%=1 TO L%\2
K%=ASC(MID$(File$,p&,1)) : p&=p&+1
Kk%=ASC(MID$(File$,p&,1)) : p&=p&+1
SELECT ON Kk%
=0:RTFtab INT((K%+1)*cWidth+.5),"L"
=1:RTFtab INT((K%+1)*cWidth+.5),"C"
=2:RTFtab INT((K%+1)*cWidth+.5),"R"
=3:RTFtab INT((K%+1)*cWidth+.5),"D"
END SELECT
NEXT I%
END IF
RTFleftIndent RTFli
' debug: PRINT LEFT$(RTFtbs$,RTFnTbs%),RTFnTbs% : MouseWait
CALL RTFbeginParagraph
REPEAT txtLoop
IF Base7&>LEN(File$) THEN EXIT txtLoop
k%=ASC(MID$(File$,Base7&,1)) : Base7&=Base7&+1
SELECT ON k%
=0:EXIT txtLoop
=9:RTFtabout
=12:DOCpagFlg%=1 ' v 1.013
=15:DOCbold
=18:DOCsuperscript
=17:DOCsubscript
=16:DOCunderline
=30:RTFoutChar "-"
=19:DOCitalic ' v 1.012, for PC Quill
=REMAINDER : RTFoutChar CHR$(k%) ' This is where it's slow!
END SELECT
END REPEAT txtLoop
CALL RTFendParagraph
END IF
END SUB
SUB DOCclearEnhance
DOCbldFlg%=0
DOCitaFlg%=0
DOCundFlg%=0
DOCcndFlg%=0
DOCsupFlg%=0
DOCsubFlg%=0
END SUB
SUB DOCbold
DOCbldFlg%=1-DOCbldFlg%
IF DOCbldFlg% THEN
CALL RTFboldON
ELSE
CALL RTFboldOFF
END IF
END SUB
SUB DOCsuperscript
DOCsupFlg%=1-DOCsupFlg%
IF DOCsupFlg% THEN
CALL RTFsuperscriptON
ELSE
CALL RTFsuperscriptOFF
END IF
END SUB
SUB DOCsubscript
DOCsubFlg%=1-DOCsubFlg%
IF DOCsubFlg% THEN
CALL RTFsubscriptON
ELSE
CALL RTFsubscriptOFF
END IF
END SUB
SUB DOCunderline
DOCundFlg%=1-DOCundFlg%
IF DOCundFlg% THEN
CALL RTFunderlineON
ELSE
CALL RTFunderlineOFF
END IF
END SUB
SUB DOCitalic
DOCitaFlg%=1-DOCitaFlg%
IF DOCitaFlg% THEN
CALL RTFitalicON
ELSE
CALL RTFitalicOFF
END IF
END SUB ' Added in v1.012 for PC Quill
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Rich Text format output routines, adapted from Mark's QL SuperBASIC
' Line numbers from the original source remain but are no longer used
2600 SUB RTFbeginDocument(OutFile$)
2610
2620 RTFbldFlg%=0
2630 RTFitaFlg%=0
2640 RTFundFlg%=0
2650 RTFcndFlg%=0
2660 RTFsupFlg%=0
2670 RTFsubFlg%=0
2680 RTFenhFlg%=1
2690
2700 RTFdefli=0
2710 RTFdeffi=0
2720 RTFdefri=0
2730 RTFli=RTFdefli
2740 RTFfi=RTFdeffi
2750 RTFri=RTFdefri
2760
2770 RTFalignFlg%=0
2780
2790 RTFstyleFlg%=0
2800 RTFparFlg%=0
2810
2820 RTFnTbs%=0
2830
2840 OPEN OutFile$ FOR OUTPUT AS #9
2850 PRINT#9,"{\rtf0 \ansi"
2860 PRINT#9,""
2870 PRINT#9,"{\fonttbl"
2880 PRINT#9,"{\f22 \fmodern Courier;}"
2890 PRINT#9,"}"
2900 PRINT#9,""
2910 PRINT#9,"{\stylesheet"
2920 PRINT#9,"{\s243 \qc \f22 \fs20 \sbasedon0 \snext243 footer;}"
2930 PRINT#9,"{\s244 \qc \f22 \fs20 \sbasedon0 \snext244 header;}"
2940 PRINT#9,"{\f22 \fs20 \sbasedon222 \snext0 Normal;}"
2950 PRINT#9,"}"
2960 PRINT#9,""
2961 RTFmargl=1080
2962 RTFmargr=11880-RTFpwid-RTFmargl
2970 PRINT#9,"\paperw11880 \paperh16800 \deftab";NUM$(INT(cWidth*5))
2975 PRINT#9,"\margl";NUM$(RTFmargl);" \margr";NUM$(RTFmargr);
PRINT#9," \margt";NUM$(-RTFmargt);" \margb";NUM$(-RTFmargb)
2980 PRINT#9,"\widowctrl \ftnbj \pgnstart";NUM$(RTFstartPag);" \fracwidth "
2985 PRINT#9,"\sectd \linemod0 \linex0 \headery";NUM$(RTFheadery);
PRINT#9," \footery";NUM$(RTFfootery);" \cols1 \endnhere"
2990 PRINT#9,"\plain \f22 \fs20 "
3000 PRINT#9,""
3010 RTFo$=""
3020 END SUB
3030
3040 SUB RTFendDocument
3050
3060 IF RTFparFlg% THEN
3070 CALL RTFendParagraph
3080 END IF
3090
3100 PRINT#9,"}"
3110 CLOSE#9
3120 END SUB
SUB RTFbeginHeader
3123 PRINT#9;"{\header "
CALL RTFbeginParagraph
RTFo$=RTFo$+"\s244 \f22 \fs20 "
END SUB
SUB RTFendHeader
3128 CALL RTFendParagraph:PRINT#9;"}":CALL RTFclearStyle
END SUB
SUB RTFbeginFooter
3133 PRINT#9;"{\footer "
CALL RTFbeginParagraph
RTFo$=RTFo$+"\s243 \f22 \fs20 "
END SUB
SUB RTFendFooter
CALL RTFendParagraph
PRINT#9;"}"
CALL RTFclearStyle
END SUB
3140 SUB RTFbeginParagraph
3150 IF rtfparFlg% THEN
3160 CALL RTFendParagraph
3200 END IF
3220 rtfparFlg%=1
3225 CALL RTFclearEnhance
3227 DOCpagFlg%=0
3230 END SUB
3250 SUB RTFendParagraph
3260 IF RTFparFlg% THEN
3270 CALL RTFendEnhance
3280 RTFo$=RTFo$+"\par "
3285 RTFflushStyle
3290 PRINT#9,RTFo$
3295 CALL RTFclearEnhance
3300 RTFo$=""
3310 rtfparFlg%=0
3315 IF DOCpagFlg%<>0 THEN
3316 CALL RTFpagebreak
3317 DOCpagFlg%=0
3318 END IF
3320 END IF
3330 END SUB
SUB RTFclearStyle
3333 RTFdefli=0
3334 RTFdeffi=0
3335 RTFdefri=0
3336 RTFli=RTFdefli
3337 RTFfi=RTFdeffi
3338 RTFri=RTFdefri
3339 :
3340 RTFalignFlg%=0
3341 :
3342 RTFnTbs%=0
3344 :
3345 RTFstyleFlg%=0
END SUB
3350 SUB RTFleftAlign
3360 IF RTFalignFlg%<>0 THEN
3370 RTFalignFlg%=0
3380 RTFstyleFlg%=1
3390 END IF
3400 END SUB
3420 SUB RTFrightAlign
3430 IF RTFalignFlg%<>1 THEN
3440 RTFalignFlg%=1
3450 RTFstyleFlg%=1
3460 END IF
3470 END SUB
3490 SUB RTFcentreAlign
3500 IF RTFalignFlg%<>2 THEN
3510 RTFalignFlg%=2
3520 RTFstyleFlg%=1
3530 END IF
3540 END SUB
3560 SUB RTFjustify
3570 IF RTFalignFlg%<>3 THEN
3580 RTFalignFlg%=3
3590 RTFstyleFlg%=1
3600 END IF
3610 END SUB
3630 SUB RTFleftIndent(N)
3640 REM n - units of pts/20 as measured from the left margin
3650 IF N<>RTFli THEN
3660 RTFli=N
3670 RTFstyleFlg%=1
3680 END IF
3682 IF RTFstyleFlg%<>0 THEN
3685 CALL RTFclearSoftTabs
3690 RTFtab N,"S"
3695 END IF
'3690 RTFtab N,"L" - previous TABless version
3700 END SUB
3720 SUB RTFfirstIndent(N)
3730 REM n - units of pts/20 as measured from the left indent
3740 IF N<>RTFfi THEN
3750 RTFfi=N
3760 RTFstyleFlg%=1
3770 END IF
3780 END SUB
3800 SUB RTFrightIndent(N)
3810 REM n - units of pts/20 as measured from the right margin
3820 IF N<>RTFri THEN
3830 RTFri=N
3840 RTFstyleFlg%=1
3850 END IF
3860 END SUB
SUB RTFclearSoftTabs
LOCAL tp$,i,j
3863 i=1
3864 REPEAT loo
3865 IF i>RTFnTbs% THEN EXIT loo
'3866 IF RTFtbs$(i)=="S" THEN
tp$=MID$(RTFtbs$,i,1)
IF tp$="S" OR tp$="s"
3867 FOR j=i TO RTFnTbs%-1
3868 RTFtbs%(j)=RTFtbs%(j+1)
3869 MID$(RTFtbs$,j,1)=MID$(RTFtbs$,j+1,1)
3870 NEXT j
3871 RTFnTbs%=RTFnTbs%-1
3872 RTFstyleFlg%=1
3873 END IF
3874 i=i+1
3875 END REPEAT loo
END SUB
3880 SUB RTFtab(N,t$)
3890 LOCAL i,j
3900 REM n - units of pts/20 as measured from the left margin
3910 REM t$ - L=left tab, C=centre tab, R=right tab, D=decimal tab
REM S=Soft tab, X=Remove old tab at this position
REM Updated from Qdos version 1.01, April/May 1996
3920
3930 i=1
3940 REPEAT poll
3950 IF ((i>RTFnTbs%) OR (RTFtbs%(i)>=N)) THEN EXIT poll
3960 i=i+1
3970 END REPEAT poll
3980
3981 IF t$=="X" THEN
3982 IF i<=RTFnTbs% THEN
3983 REM remove old tab
3984 FOR j=i TO RTFnTbs%-1
3985 RTFtbs%(j)=RTFtbs%(j+1)
MID$(RTFtbs$,j,1)=MID$(RTFtbs$,j+1,1)
NEXT j
3988 RTFnTbs%=RTFnTbs%-1
3989 RTFstyleFlg%=1
3990 END IF
3991 ELSE
' PRINT n;t$;i;"of";RTFnTbs% : MouseWait ' Debug line
3992 IF i>RTFnTbs% THEN
3995 REM add new tab to end of Q
4000 RTFnTbs%=RTFnTbs%+1
4010 RTFtbs%(RTFnTbs%)=N
4020 MID$(RTFtbs$,RTFnTbs%,1)=t$
4030 RTFstyleFlg%=1
4040 ELSE
4050 IF N=RTFtbs%(i) THEN
4055 REM Replace old tab with new
IF t$<>"S" AND t$<>"s"
4060 IF MID$(RTFtbs$,i,1)<>t$ THEN
4070 MID$(RTFtbs$,i,1)=t$
4080 RTFstyleFlg%=1
4090 END IF
4095 END IF
4100 ELSE
4105 REM Insert new tab
4110 RTFnTbs%=RTFnTbs%+1
4120 FOR j=RTFnTbs%-1 TO i STEP -1
4130 RTFtbs%(j+1)=RTFtbs%(j)
4140 MID$(RTFtbs$,(j+1),1)=MID$(RTFtbs$,j,1)
4150 NEXT j
4160 RTFtbs%(i)=N
4170 MID$(RTFtbs$,i,1)=t$
4180 RTFstyleFlg%=1
4190 END IF
4200 END IF
4210 END IF
4220 END SUB
4230
4240 SUB RTFflushStyle
4250 LOCal i,t,t$
4260
4270 IF RTFstyleFlg% THEN
4280 t=RTFalignFlg%
4290 SELect ON t
4300 =0:t$="\pard "
4310 =1:t$="\pard \qr "
4320 =2:t$="\pard \qc "
4330 =3:t$="\pard \qj "
4340 END SELECT
4355 t$=t$+"\sl"+NUM$(RTFleading)+" "
4360 IF RTFli<>RTFdefli THEN
4370 t$=t$ + "\li" + NUM$(RTFli) + " "
4380 END IF
4390
4400 IF RTFfi<>RTFdeffi THEN
4410 t$=t$ + "\fi" + NUM$(RTFfi) + " "
4420 END IF
4430
4440 IF RTFri<>RTFdefri THEN
4450 t$=t$ + "\ri" + NUM$(RTFri) + " "
4460 END IF
4470
4480 IF RTFnTbs%<>0 THEN
4490 FOR i=1 TO RTFnTbs%
4500 t=ASC(MID$(RTFtbs$,i,1))
4510 SELect ON t
4520 =ASC("L"),ASC("S")
4530 REM left tab or soft tab (v1.01)
4540 t$=t$ + "\tx" + NUM$(RTFtbs%(i)) + " "
4550 =ASC("C")
4560 REM centre tab
4570 t$=t$ + "\tqc\tx" + NUM$(RTFtbs%(i)) + " "
4580 =ASC("R")
4590 REM right tab
4600 t$=t$ + "\tqr\tx" + NUM$(RTFtbs%(i)) + " "
4610 =ASC("D")
4620 REM decimal tab
4630 t$=t$ + "\tqdec\tx" + NUM$(RTFtbs%(i)) + " "
4640 END SELect
4650 NEXT i
4660 END IF
4670
4680 RTFo$=t$ + RTFo$
4690
4700 RTFstyleFlg%=0
4710 END IF
4720 END SUB
4740 SUB RTFboldON
4750 IF RTFbldFlg%=0 THEN
4760 CALL RTFendEnhance
4770 RTFbldFlg%=1
4775 RTFenhFlg%=1 ' 1.01
4780 END IF
4790 END SUB
4810 SUB RTFboldOFF
4820 IF RTFbldFlg%<>0 THEN
4830 RTFendEnhance
4840 RTFbldFlg%=0
4845 RTFenhFlg%=RTFbldFlg% OR RTFitaFlg% OR RTFundFlg% OR RTFcndFlg% OR RTFsupFlg% OR RTFsubFlg%
4850 END IF
4860 END SUB
4880 SUB RTFitalicON
4890 IF RTFitaFlg%=0 THEN
4900 CALL RTFendEnhance
4910 RTFitaFlg%=1
4915 RTFenhFlg%=1
4920 END IF
4930 END SUB
4950 SUB RTFitalicOFF
4960 IF RTFitaFlg%<>0 THEN
4970 CALL RTFendEnhance
4980 RTFitaFlg%=0
4990 END IF
5000 END SUB
5020 SUB RTFunderlineON
5030 IF RTFundFlg%=0 THEN
5040 CALL RTFendEnhance
5050 RTFundFlg%=1
RTFenhFlg%=1
5060 END IF
5070 END SUB
5090 SUB RTFunderlineOFF
5100 IF RTFundFlg%<>0 THEN
5110 CALL RTFendEnhance
5120 RTFundFlg%=0
RTFenhFlg%=RTFbldFlg% OR RTFitaFlg% OR RTFundFlg% OR RTFcndFlg% OR RTFsupFlg% OR RTFsubFlg%
RTFenhFlg%=1
5130 END IF
5140 END SUB
5160 SUB RTFcondensedON
5170 IF RTFcndFlg%=0 THEN
5180 CALL RTFendEnhance
RTFenhFlg%=1
5190 RTFcndFlg%=1
5200 END IF
5210 END SUB
5230 SUB RTFcondensedOFF
5240 IF RTFcndFlg%<>0 THEN
5250 CALL RTFendEnhance
5260 RTFcndFlg%=0
RTFenhFlg%=RTFbldFlg% OR RTFitaFlg% OR RTFundFlg% OR RTFcndFlg% OR RTFsupFlg% OR RTFsubFlg%
5270 END IF
5280 END SUB
5300 SUB RTFsuperscriptON
5310 IF RTFsupFlg%=0 THEN
5320 CALL RTFendEnhance
RTFenhFlg%=1
5330 RTFsupFlg%=1
5340 END IF
5350 END SUB
5370 SUB RTFsuperscriptOFF
5380 IF RTFsupFlg%<>0 THEN
5390 CALL RTFendEnhance
5400 RTFsupFlg%=0
RTFenhFlg%=RTFbldFlg% OR RTFitaFlg% OR RTFundFlg% OR RTFcndFlg% OR RTFsupFlg% OR RTFsubFlg%
5410 END IF
5420 END SUB
5440 SUB RTFsubscriptON
5450 IF RTFsubFlg%=0 THEN
5460 CALL RTFendEnhance
RTFenhFlg%=1
5470 RTFsubFlg%=1
5480 END IF
5490 END SUB
5510 SUB RTFsubscriptOFF
5520 IF RTFsubFlg%<>0 THEN
5530 CALL RTFendEnhance
5540 RTFsubFlg%=0
RTFenhFlg%=RTFbldFlg% OR RTFitaFlg% OR RTFundFlg% OR RTFcndFlg% OR RTFsupFlg% OR RTFsubFlg%
5550 END IF
5560 END SUB
' The following subroutine is no longer needed
'5580 SUB RTFbeginEnhance
'5590 IF RTFenhFlg%=0 THEN
'5600 RTFo$=RTFo$ + "}"
'5610 RTFbldFlg%=0
'5620 RTFitaFlg%=0
'5630 RTFundFlg%=0
'5640 RTFcndFlg%=0
'5650 RTFsupFlg%=0
'5660 RTFsubFlg%=0
'5670 RTFenhFlg%=1
'5680 END IF
SUB RTFendEnhance
5590 IF RTFenhFlg%=0 THEN
5595 IF (RTFbldFlg% OR RTFitaFlg% OR RTFundFlg% OR RTFcndFlg% OR RTFsupFlg% OR RTFsubFlg%) THEN
5600 RTFo$=RTFo$+"}"
5605 END IF
5606 END IF
5607 END SUB
SUB RTFclearEnhance
5610 RTFbldFlg%=0
5620 RTFitaFlg%=0
5630 RTFundFlg%=0
5640 RTFcndFlg%=0
5650 RTFsupFlg%=0
5660 RTFsubFlg%=0
5670 RTFenhFlg%=0
5690 END SUB
5710 SUB RTFflushEnhance
5720 IF RTFenhFlg% THEN
5730 RTFo$=RTFo$ + "{"
5740 IF RTFbldFlg% THEN
5750 RTFo$=RTFo$ + "\b "
5760 END IF
5770 IF RTFitaFlg% THEN
5780 RTFo$=RTFo$ + "\i "
5790 END IF
5800 IF RTFundFlg% THEN
5810 RTFo$=RTFo$ + "\ul "
5820 END IF
5830 IF RTFcndFlg% THEN
5840 RTFo$=RTFo$ + "\expnd58 "
5850 END IF
5860 IF RTFsupFlg% THEN
5870 RTFo$=RTFo$ + "\up6 "
5880 END IF
5890 IF RTFsubFlg% THEN
5900 RTFo$=RTFo$ + "\dn4 "
5910 END IF
5920 END IF
5930 RTFenhFlg%=0
5940 END SUB
SUB RTFtabout
5952 IF RTFenhFlg% THEN CALL RTFflushEnhance
5953 RTFo$=RTFo$+"\tab "
END SUB
SUB RTFpagebreak
5957 PRINT#9;"\page "
END SUB
5960 SUB RTFoutChar(t$)
5965 LOCAL K%,C%
5970 IF RTFenhFlg% THEN
5980 CALL RTFflushEnhance
5990 END IF
K%=ASC(t$)
5993 SELECT ON K%
5995 =ASC("{"),ASC("}"),ASC("\"):RTFo$=RTFo$+"\"+t$
5996 =32 TO 126:RTFo$=RTFo$+t$
=127 TO 255
C%=ANSI%(K%)
' PRINT "In: ";K%;" -> ";C% : MouseWait
IF C%<128 THEN
RTFo$=RTFo$+CHR$(C%)
ELSE
RTFo$=RTFo$+"\'"+HEX8$(C%)
END IF
5998 =REMAINDER
RTFo$=RTFo$+"\'"+HEX8$(C%) ' Control codes?!
6000 END SELECT
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
REM Character code conversion tables
REM PC ASCII TO ANSI CODE CONVERSION TABLE, PROVIDED BY CHAS DILLON
PC_CODES:
DATA 63, 199, 252 : ' 127 - 129
DATA 233, 226, 228, 224, 229, 231, 234, 235, 232, 239 : ' 130 - 139
DATA 238, 236, 196, 197, 201, 230, 198, 244, 246, 243 : ' 140 - 149
DATA 251, 249, 255, 214, 220, 162, 163, 165, 63, 63 : ' 150 - 159
DATA 225, 237, 243, 250, 241, 209, 63, 186, 191, 63 : ' 160 - 169
DATA 172, 189, 188, 161, 171, 187, 63, 63, 63, 63 : ' 170 - 179
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 180 - 189
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 190 - 199
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 200 - 209
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 210 - 219
DATA 63, 63, 63, 63, 63, 223, 63, 63, 63, 63 : ' 220 - 229
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 230 - 239
DATA 63, 63, 63, 63, 63, 63, 247, 63, 63, 63 : ' 240 - 249
DATA 63, 63, 63, 178, 63, 63 : ' 250 - 255
REM Untranslatable codes replaced with 63 to display as question marks.
REM German Sz/Greek Beta (ANSI 223) added by SNG at table position 225.
REM Use this to translate PC Quill accented and extra (non 7 bit ASCII)
REM codes to `standard' ANSI codes, used by Amiga and Windoze programs.
REM It includes French E, A and U grave, E acute, C circumflex, Spanish
REM N tildes & inverted ? and !, German Beta/Sz and O, A and U umlauts.
REM QL ASCII TO ANSI CODE CONVERSION TABLE, ENTERED BY SIMON N GOODWIN.
QL_CODES:
DATA 169, 228, 227 : ' 127 .. 129
DATA 229, 233, 246, 245, 248, 252, 231, 241, 230, 69 : ' 130 .. 139
DATA 225, 224, 226, 235, 232, 234, 239, 237, 236, 238 : ' 140 .. 149
DATA 243, 242, 244, 250, 249, 251, 223, 162, 165, 96 : ' 150 .. 159
DATA 196, 195, 197, 201, 214, 213, 216, 220, 199, 209 : ' 160 .. 169
DATA 198, 63, 63, 240, 63, 63, 181, 63, 63, 161 : ' 170 .. 179
DATA 191, 63, 167, 164, 171, 187, 176, 247, 63, 63 : ' 180 .. 189
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 190 .. 199
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 200 .. 209
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 210 .. 219
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 220 .. 229
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 230 .. 239
DATA 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 : ' 240 .. 249
DATA 63, 63, 63, 63, 63, 63 : ' 250 .. 255
' MISSING: oe/OE ellipsis (139, 171), Alpha, Theta, Lambda, Pi, Phi (172,
' 174, 175, 177, 178), Backward S (181), arrowheads (188, 189, 190, 191).
' Amiga codes from Mapping the Amiga - checked by inspection of Topaz and
' Clean fonts - note: the table in the A2000 Amiga BASIC manual is WRONG!
' This SuperBASIC show Qdos codes: FOR I=127 TO 191 : PRINT I!!CHR$(I)!!!
' This table translates QL & Thor Quill accents and other non 7 bit ASCII
' codes into the ANSI character codes used by Amiga AND Windoze programs.